package com.chucknorris.android.ui;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

import com.chucknorris.android.R;

public class SplashActivity extends Activity {
	private static final long SPLASH_DISPLAY_LENGTH = 1500;
	private Random generator = new Random();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		ImageView splash = (ImageView) findViewById(R.id.splash);
		int[] images = new int[] { R.drawable.chuck1, R.drawable.chuck2, R.drawable.chuck3, R.drawable.chuck4, R.drawable.chuck5 };
		int randomPosition = generator.nextInt(images.length);
		splash.setImageResource(images[randomPosition]);
		
		/*
		Cursor cursor = getContentResolver().query(Chuck.CONTENT_URI, ChuckQuery.PROJECTION, null, null, Chuck.DEFAULT_SORT);
		cursor.moveToFirst();
		do {

			long id = cursor.getLong(ChuckQuery._ID);
			String topic = cursor.getString(ChuckQuery.TOPIC);
			ContentValues values = new ContentValues();
			try {
				values.put(ChuckColumns.TOPIC.getName(), SimpleCrypto.encrypt(ChuckActivity.SEED, topic));
			} catch (Exception e) {
				e.printStackTrace();
			}
			getContentResolver().update(Chuck.CONTENT_URI, values, ChuckColumns._ID.getName() + " =? ", new String[] { String.valueOf(id) });
			Log.e("count", "" + cursor.getCount());

		} while (cursor.moveToNext());
		cursor.close();
		*/

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {

				final Intent mainIntent = new Intent(SplashActivity.this, ChuckActivity.class);
				startActivity(mainIntent);
				finish();
			}
		}, SPLASH_DISPLAY_LENGTH);

	}

}
